package ro.gillardon.persistence.document.model;

import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Set;

import com.orientechnologies.orient.core.record.impl.ODocument;
/**
 * Contains methods and details specific to a reservation (user, startDate, endDate...).
 *
 * @author haiurar
 */
public class Reservation extends ODocumentClass {
  private static final String TOTAL = "total";
  private static final String COST = "cost";
  private static final String SUBSISTENCE = "subsistence";
  private static final String OBSERVATIONS = "observations";
  private static final String MOT_ARRAY = "motArray";
  private static final String HOTEL_RESERVATION_ARRAY = "hotelReservationArray";
  private static final String START_DATE = "startDate";
  private static final String USER = "user";
  private static final String END_DATE = "endDate";

  /**
   * Instantiates a new reservation.
   *
   * @param user the user
   * @param startDate the starting date
   * @param endDate the end date
   * @param hotelReservationArray the hotel reservations for the user
   * @param motArray the means of transport used by the user
   * @param observations the observations
   * @param subsistence the subsistence/day
   * @param cost the cost
   * @param total the total cost
   */
  public Reservation(final LocalDateTime startDate, final LocalDateTime endDate,
    final String observations,
    final double subsistence, final double cost, final double total) {
    super();
    this.doc.field(START_DATE, startDate);
    this.doc.field(END_DATE, endDate);
    this.doc.field(OBSERVATIONS, observations);
    this.doc.field(SUBSISTENCE, subsistence);
    this.doc.field(COST, cost);
    this.doc.field(TOTAL, total);

  }

  public void setMotArray(final Set<Mot> motArray) {
    Set<ODocument> motArrayDocument = new HashSet<ODocument>();
    for (Mot mot : motArray) {
      motArrayDocument.add(mot.getDoc());
    }
    this.doc.field(MOT_ARRAY, motArrayDocument);
  }

  public void setHotelReservation(final Set<HotelReservation> hotelReservationArray) {
    Set<ODocument> hotelReservationDocument = new HashSet<ODocument>();
    for (HotelReservation hr : hotelReservationArray) {
      hotelReservationDocument.add(hr.getDoc());
    }
    this.doc.field(HOTEL_RESERVATION_ARRAY, hotelReservationDocument);
  }

  public void setUser(final User user) {
    this.doc.field(USER, user.getDoc());
  }

  /**
   * Gets the user.
   *
   * @return the user
   */
  public User getUser() {
    return this.doc.field(USER);
  }

  /**
   * Gets the startDate.
   *
   * @return the startDate
   */
  public LocalDateTime getStartDate() {
    return this.doc.field(START_DATE);
  }

  /**
   * Gets the endDate.
   *
   * @return the endDates
   */
  public LocalDateTime getEndDate() {
    return this.doc.field(END_DATE);
  }

  /**
   * Gets the hotel reservations for the user.
   *
   * @return the hotel reservations for the user
   */
  public Set<HotelReservation> getHotelReservationArray() {
    return this.doc.field(HOTEL_RESERVATION_ARRAY);
  }

  /**
   * Gets the means of transport used by the user.
   *
   * @return the means of transport used by the user
   */
  public Set<Mot> getMotArray() {
    return this.doc.field(MOT_ARRAY);
  }

  /**
   * Gets the observations.
   *
   * @return the observations
   */
  public String getObservations() {
    return this.doc.field(OBSERVATIONS);
  }

  /**
   * Gets the subsistence.
   *
   * @return the subsistence
   */
  public double getSubsistence() {
    return this.doc.field(SUBSISTENCE);
  }

  /**
   * Gets the costs.
   *
   * @return the costs
   */
  public double getCost() {
    return this.doc.field(COST);
  }

  /**
   * Gets the total.
   *
   * @return the total
   */
  public double getTotal() {
    return this.doc.field(TOTAL);
  }

}
